package com.xinlu.util.tool;

import java.util.ArrayList;
import java.util.List;

public class DealCodeinfoUtils {
	
	public static void main(String[] args) {
		
		System.out.println(dealCodes("12,3,5$22,4,5"));
	}

	public static String dealCodes(String codes) {

		String[] cods = codes.split("\\$");
		String allCodes = "";
		List<String> numList = null;
		List<String> allList = null;

		if (cods != null && cods.length > 0) {

			String[] num = null;
			allList = new ArrayList<String>();

			for (String str : cods) {
				numList = new ArrayList<String>();
				num = str.split(",");

				for (String str2 : num) {
					List<String> tempList = new ArrayList<String>(numList);
					if (str2.length() > 1) {

						for (int i = 0; i < str2.length(); i++) {

							if (i == 0) {

								if (numList.size() > 0) {

									for (int j = 0; j < numList.size(); j++) {

										numList.set(j, numList.get(j) + ","
												+ str2.substring(i, i + 1));
									}
								} else {

									numList.add(str2.substring(i, i + 1));
								}
							} else {

								List<String> list = new ArrayList<String>(
										tempList);

								if (list.size() > 0) {

									for (int j = 0; j < list.size(); j++) {

										list.set(j, list.get(j) + ","
												+ str2.substring(i, i + 1));
									}
								} else {

									list.add(str2.substring(i, i + 1));
								}

								numList.addAll(list);
							}

						}
					} else {

						if (numList.size() > 0) {

							for (int j = 0; j < numList.size(); j++) {

								numList.set(j, numList.get(j) + "," + str2);
							}
						} else {

							numList.add(str2);
						}
					}
				}

				allList.addAll(numList);
			}
		}

		String reStr = "";

		for (String string : allList) {

			reStr += string + "$";
		}

		return reStr.substring(0, reStr.length() - 1);
	}
}
